package pers.fulsun.demo.springcloud.service.impl;

import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import org.springframework.transaction.annotation.Transactional;
import pers.fulsun.demo.springcloud.entity.UserTotal;
import pers.fulsun.demo.springcloud.mapper.UserTotalMapper;
import pers.fulsun.demo.springcloud.service.UserTotalService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author fulsun
 * @since 2021-09-18
 */
@Service
public class UserTotalServiceImpl extends ServiceImpl<UserTotalMapper, UserTotal> implements UserTotalService {
    @Transactional //本地事务注解
    @LcnTransaction //分布式事务注解
    public void incr(String name) {
        try {
            Thread.sleep(5000); //线程休眠5秒，造成访问超时
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        UserTotal userTotal = new UserTotal();
        userTotal.setCreateBy(name);
        userTotal.setTotal(1L);
        this.baseMapper.insert(userTotal);
    }
}
